<template>
  <div>
    <el-row>
      <el-button size="mini" @click="addCms"> 新增 </el-button>
      <el-button size="mini" @click="openData"> 刷新 </el-button>
    </el-row>
    <div style="height: 15px"></div>
    <el-dialog title="Cms系统" v-model="FShowCmsEdit" destroy-on-close>
      <el-form :model="FIndexCms" label-width="80px">
        <el-form-item label="Cms编码">
          <el-input v-model="FIndexCms.FCMSCode"></el-input>
        </el-form-item>
        <el-form-item label="Cms名称">
          <el-input v-model="FIndexCms.FCMSName"></el-input>
        </el-form-item>
        <el-form-item label="Cms类别">
          <el-select v-model="FIndexCms.FCMSClass" placeholder="请选择">
            <el-option
              v-for="item in FCmsClassList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="FShowCmsEdit = false">取 消</el-button>
          <el-button type="primary" @click="saveCms">确 定</el-button>
        </span>
      </template>
    </el-dialog>
    <el-table :data="FCmsList">
      <el-table-column prop="FCMSCode" label="CMS编码" />
      <el-table-column prop="FCMSName" label="CMS名称" />
      <el-table-column prop="FCMSClass" label="CMS类别" />
      <el-table-column label="操作">
        <template #default="scope">
          <el-button
            type="primary"
            plain
            icon="el-icon-edit"
            size="mini"
            @click="editCms(scope.row)"
            >编辑</el-button
          >
          <el-button
            type="primary"
            plain
            icon="el-icon-edit"
            size="mini"
            @click="editCmsMenu(scope.row)"
            >菜单模块设计</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script lang="ts">
import { TBaseCms } from "@/baselib/module/cms/BaseCmsApi";
import { IMenuItem } from "@/store";
import TFormBase from "@/views/BaseForm";
export default class TFormCmsList extends TFormBase {
  private FShowCmsEdit: boolean = false;
  private FIndexCms: TBaseCms = new TBaseCms();
  private FCmsList: TBaseCms[] = [];
  private FCmsClassList: any = [
    { value: "内容系统", label: "内容系统" },
    { value: "问题系统", label: "问题系统" },
  ];
  public created() {
    this.openData();
  }
  private async openData() {
    var lResult = await this.$myBaseCms.GetCmsList();
    if (!lResult.resultSuccess) {
      this.$myMsgHelp.msgDialog(lResult.resultMsg);
      return;
    }
    this.FCmsList = lResult.resultData;
    this.$myMsgHelp.msgHintAutoClose("刷新数据成功");
  }
  private addCms() {
    this.FIndexCms = new TBaseCms();
    this.FShowCmsEdit = true;
  }
  private editCms(qCms: TBaseCms) {
    //
    this.FIndexCms = qCms;
    this.FShowCmsEdit = true;
  }
  private async saveCms() {
    this.FShowCmsEdit = false;
    var lResult = await this.$myBaseCms.SaveCms(this.FIndexCms);
    if (!lResult.resultSuccess) {
      this.$myMsgHelp.msgDialog(lResult.resultMsg);
      return;
    }
    this.$myMsgHelp.msgHintAutoClose("保存数据成功");
    this.openData();
  }
  private async editCmsMenu(qCms: TBaseCms) {
    let lTag: IMenuItem = {
      menuIndexName: "TFormCmsMenu-" + qCms.FCMSID,
      menuComponent: "TFormCmsMenu",
      menuTitle: "CMS菜单_" + qCms.FCMSName,
      menuIcon: "",
      menuParams: { CMSID: qCms.FCMSID }, //参数
      menuChildren: [],
    };
    this.$myEvenBus.addTag(lTag);
  }
}
</script>

